Completed
Push — master ( 5ac0c3...6da433 )
by greg
02:29
created

operations.js ➔ describe(ꞌCreateꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
cc 1
c 2
b 2
f 0
nc 1
dl 0
loc 56
rs 9.7251
nop 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A operations.js ➔ ... ➔ before 0 15 1
A operations.js ➔ ... ➔ it(ꞌcmsOperations.create()ꞌ) 0 13 1
A operations.js ➔ ... ➔ it(ꞌcmsOperations.duplicate()ꞌ) 0 12 1
A operations.js ➔ ... ➔ it(ꞌcmsOperations.duplicate() updateꞌ) 0 11 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var chai = require('chai');
2
var path = require('path');
3
4
var config = require('../src/cli').config
5
config.set({root: path.join(__dirname,'fixtures')})
6
7
var cmsOperations = require('../src/cli').cmsOperations
8
var Manager = require('../src/cli').Manager;
9
var fse = require('fs-extra');
10
11
describe('Create', function() {
12
  before( function(done) {
13
    Manager.instance.init()
14
      .then(function () {
15
        Manager.instance._whereKeys = ['title', 'priority', 'abe_meta', 'articles']
16
        Manager.instance.updateList()
17
18
        this.fixture = {
19
          tag: fse.readFileSync(path.join(__dirname, 'fixtures/templates/article.html'), 'utf8'),
20
          jsonArticle: fse.readJsonSync(path.join(__dirname, '/fixtures/files/article-4.json')),
21
          jsonHomepage: fse.readJsonSync(path.join(__dirname, '/fixtures/data/homepage-1.json'))
22
        }
23
        done()
24
        
25
      }.bind(this))
26
  });
27
28
  it('cmsOperations.create()', function(done) {
29
    cmsOperations.create('article', '', 'article-2.html', {query: ''}, this.fixture.jsonArticle, false)
30
      .then(function(resSave) {
31
        var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json'))
32
        console.log(json)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
33
        var stat = fse.statSync(json)
34
        if (stat) {
35
          chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
36
        }
37
        fse.removeSync(json)
38
        done()
39
      }.bind(this));
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
40
  });
41
42
  it('cmsOperations.duplicate()', function(done) {
43
    cmsOperations.duplicate('article-1.html', 'article', '', 'article-2.html', {}, false)
44
    .then(function(resSave) {
45
      var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json'))
46
      var stat = fse.statSync(json)
47
      if (stat) {
48
        chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
49
      }
50
      fse.removeSync(json)
51
      done()
52
    }.bind(this))
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
53
  });
54
55
  it('cmsOperations.duplicate() update', function(done) {
56
    cmsOperations.duplicate('article-1.html', 'article', '', 'article-1.html', {}, true)
57
    .then(function(resSave) {
58
      var json = path.join(config.root, config.data.url, resSave.abe_meta.link.replace('.html', '.json'))
59
      var stat = fse.statSync(json)
60
      if (stat) {
61
        chai.expect(stat).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(stat).to.not.be.undefined is not used.
Loading history...
62
      }
63
      done()
64
    }.bind(this))
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
65
  });
66
});
67